package test2;

import java.util.Scanner;

public class StateMachine {
    enum State {
        INITIAL, STATE_1, STATE_2
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        State currentState = State.INITIAL;
        boolean exit = false;
        while (!exit) {
            System.out.println("Current state: " + currentState);
            System.out.println("Enter a command (1, 2, exit):");
            String command = scanner.nextLine();
            switch (command) {
                case "1":
                    switch (currentState) {
                        case INITIAL:
                            System.out.println("Entering State 1");
                            currentState = State.STATE_1;
                            break;
                        case STATE_1:
                            System.out.println("Already in State 1");
                            break;
                        case STATE_2:
                            System.out.println("Cannot enter State 1 from State 2");
                            break;
                    }
                    break;
                case "2":
                    switch (currentState) {
                        case INITIAL:
                            System.out.println("Cannot enter State 2 from initial state");
                            break;
                        case STATE_1:
                            System.out.println("Entering State 2");
                            currentState = State.STATE_2;
                            break;
                        case STATE_2:
                            System.out.println("Already in State 2");
                            break;
                    }
                    break;
                case "exit":
                    exit = true;
                    break;
                default:
                    System.out.println("Unknown command");
                    break;
            }
        }
    }
}
